package com.lxt.filemanager.common;



import org.csource.common.MyException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * 全局异常处理
 */
@ControllerAdvice(annotations = {Controller.class})
public class GlobalExceptionHandler {

    /**
     * 文件传输错误
     */
    @ExceptionHandler(IOException.class)
    public ModelAndView fileIOError(IOException ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("message",ex.getMessage());
        ex.printStackTrace();
        return modelAndView;
    }
    /**
     * fdfs错误
     */
    @ExceptionHandler(MyException.class)
    public ModelAndView fastDfsError(IOException ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("message",ex.getMessage());
        ex.printStackTrace();
        return modelAndView;
    }
}
